﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Carbon.Web.Forms.Extensions;

namespace Demo.Demos.ComplexDataStructures
{
    public partial class TreeViewNode : System.Web.UI.UserControl
    {
        protected void Click_ToggleExpanded(object sender, EventArgs args)
        {
            PersonViewModel person = (PersonViewModel)((Control)sender).GetViewModelContext();

            person.IsNodeExpanded = !person.IsNodeExpanded;
        }

        protected void Click_SelectItem(object sender, EventArgs args)
        {
            PersonViewModel person = (PersonViewModel)((Control)sender).GetViewModelContext();

            person.SelectCurrent();
        }

        protected void Click_AddNew(object sender, EventArgs args)
        {
            PersonViewModel person = (PersonViewModel)((Control)sender).GetViewModelContext();

            person.AddNewSubordinate(new PersonViewModel(person.RootViewModel) { IsNodeExpanded = false });    
        }

        public String GetHandleClass()
        {
            PersonViewModel person = (PersonViewModel)this.GetViewModelContext();

            return "d-tree-item-node-handle " + (person.IsNodeExpanded ? "expanded" : "");
        }

        public String GetItemClass()
        {
            PersonViewModel person = (PersonViewModel)this.GetViewModelContext();

            return "d-tree-item-title " + (person.IsSelected ? "selected" : "");
        }
    }
}